#include "block.h"

static void drawBlock(SDL_Surface* dest, void* this);

Block* createBlock(int x, int y, Colour colour) {
	Block* block = (Block*)createObject(sizeof(Block));
	block->colour = colour;
	block->destroyed = FALSE;
	block->x = x;
	block->y = y;
	block->draw = &drawBlock;

	block->rectLeft = createObject(sizeof(SDL_Rect));
	block->rectLeft->x = x;
	block->rectLeft->y = y+1;
	block->rectLeft->w = 1;
	block->rectLeft->h = BLOCK_HEIGHT-1;

	block->rectRight = createObject(sizeof(SDL_Rect));
	block->rectRight->x = x+BLOCK_WIDTH;
	block->rectRight->y = y+1;
	block->rectRight->w = 1;
	block->rectRight->h = BLOCK_HEIGHT-1;

	block->rectTop = createObject(sizeof(SDL_Rect));
	block->rectTop->x = x+1;
	block->rectTop->y = y;
	block->rectTop->w = BLOCK_WIDTH-1;
	block->rectTop->h = 1;

	block->rectBottom = createObject(sizeof(SDL_Rect));
	block->rectBottom->x = x+1;
	block->rectBottom->y = y+BLOCK_HEIGHT;
	block->rectBottom->w = BLOCK_WIDTH-1;
	block->rectBottom->h = 1;

	return block;
}

static void drawBlock(SDL_Surface* dest, void* this) {
	Block* block = (Block*)this;
	if(block->destroyed)
		return;
	rectangleColor(dest, block->x, block->y, block->x+BLOCK_WIDTH, block->y+BLOCK_HEIGHT, convertToRGBABrightness(block->colour, 100));
	boxColor(dest, block->x+1, block->y+1, block->x+BLOCK_WIDTH-1, block->y+BLOCK_HEIGHT-1, convertToRGBA(block->colour));
}
